import { createRouter, createWebHistory } from 'vue-router'
import { localeData } from '@/lang/index.js'

import { routes } from './routes'
import { parseUrlParams } from '@/utils/util.js'
// import config from '@/config'

const routerHistory = createWebHistory('/activity/mango_mobile/')
// const routerHistory = createWebHashHistory()
const router = createRouter({
  history: routerHistory,
  routes
})

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }

router.beforeEach((to, from, next) => {
  parseUrlParams()
  const { meta } = to
  const { locale, messages } = localeData
  const newLocale = ['en', 'es'].includes(locale) ? locale : 'en'
  switch (meta.title) {
    case 'DailyFreeCoinsRule':
      document.title = messages[newLocale]['dailyFreeCoinTitle']
      break
    case 'RechargingRule':
      document.title = messages[newLocale]['rechargingTitle']
      break
    default:
      document.title = meta.title
  }

  next()
})
export default router
